/* eslint-disable */
<script>
import { setStorage } from './utils/microApi'
import { getConfigByGroup, getShare } from './api/common'
export default {
  onError(err) {
    console.log('捕捉错误：', err)
    this.$f.log(err)
  },
  onLaunch(argData) {
    console.log('onLaunch', process.env)
    console.log('params:', argData)
    // #ifdef  MP-WEIXIN
    try {
      wx.cloud.init({
        traceUser: true
      })
    } catch (err) {
      console.error(err)
    }
    // #endif
    // 记录首次加载打开参数
    setStorage('openPage', argData.path)
    setStorage('openQuery', argData.query)
    // #ifdef H5
    if (
      process.env.NODE_ENV === 'development' ||
      window.location.host.match('gzgjjtest.gdtengnan.com') ||
      window.location.port === '8001'
    ) {
      var VConsole = require('vconsole')
      // eslint-disable-next-line no-undef
      var vConsole = new VConsole()
      console.log('vconsole开启')
    }
    this.getShare()
    // #endif
  },
  // 只有app.vue的onshow有参数
  onShow(argData) {
    console.log('App Show params:', argData)
  },
  onHide() {
    console.log('App Hide')
  },
  methods: {
    async getShare() {
      let data = {
        acode: 'newtime',
        js_url: window.location.href
      }
      let sigeData = await getShare(data)
      data = {
        group_name: 'wechat'
      }
      let shareData = await getConfigByGroup(data)
      var wxsdk = require('weixin-js-sdk')
      if (!sigeData.jsApiList) {
        sigeData.jsApiList = [
          'onMenuShareTimeline',
          'onMenuShareAppMessage',
          'onMenuShareQQ',
          'onMenuShareWeibo',
          // 'updateAppMessageShareData',
          // 'updateTimelineShareData',
          'onMenuShareAppMessage',
          'onMenuShareQZone'
        ]
      }
      // const sharelink = this.getHomeUrl()
      wxsdk.config({
        debug: !!sigeData.debug,
        appId: sigeData.appId || '',
        timestamp: sigeData.timestamp || '',
        nonceStr: sigeData.nonceStr || '',
        signature: sigeData.signature || '',
        jsApiList: sigeData.jsApiList || []
      })
      let shareInfo = {
        title: shareData.share_title.value || '', // 分享标题
        desc: shareData.share_content.value || '', // 分享描述
        link: '', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: shareData.share_image.value || '', // 分享图标
        success: function () {
          // 设置成功
        }
      }
      wxsdk.ready(() => {
        // 分享到朋友圈
        wxsdk.onMenuShareTimeline(shareInfo)
        // wxsdk.updateAppMessageShareData(shareInfo)
        // 分享给朋友
        wxsdk.onMenuShareAppMessage(shareInfo)
        // wxsdk.updateTimelineShareData(shareInfo)
      })
    },
  }
}
</script>

<style lang="scss">
@import './scss/settings';
@import './scss/base';
// iconf
page,
body {
  .i {
    font-size: inherit;
  }
  /* #ifdef APP-PLUS */
  .uni-list {
    .uni-list-item__container {
      border-top-width: 0;
    }
  }
  /* #endif */
}
// icon处理 大于10K图标放static/icon下或在css中引入
.i-del {
  @include iIcon(i-del, 20);
}
.i-add {
  @include iIcon(i-add, 30);
}
</style>
